package com.ceair.flight.refund.location.model;

import com.ceair.muservice.common.dto.AbstractBaseDO;
import org.apache.ibatis.type.Alias;

import java.io.Serializable;
import java.math.BigDecimal;
import java.util.*;

@Alias("paxDO")
public class PaxDO extends AbstractBaseDO implements Serializable { // 旅客表

    private static final long serialVersionUID = -2538590742581640592L;
    /**
     * 乘客id *
     */
    private Long passengerId;
    /**
     * 乘客改期前的id *
     */
    private Long oldPassengerId;
    /**
     * 状态	待开票 已开票 已退票 已改期 已升舱 已挂起*
     */
    private Integer modifySt;
    /**
     * 票号 *
     */
    private String tktNo;
    /**
     * 旅客姓 *
     */
    private String passengerFirstName;
    /**
     * 旅客中间名（外国名） *
     */
    private String passengerMiddleName;
    /**
     * 旅客名 *
     */
    private String passengerLastName;
    /**
     * 旅客生日 *
     */
    private String passengerBirthday;
    /**
     * 性别 *0 男 1 女
     */
    private String passengerSex;
    /**
     * 国籍 *
     */
    private String country;
    /**
     * 常旅客卡号 *
     */
    private String ffp;
    /**
     * 证件类型 NI身份证 PP护照 ID其他*
     */
    private String passTp;
    /**
     * 证件号码 *
     */
    private String passNo;
    /**
     * 证件有效期 *
     */
    private String passValidDt;
    /**
     * 发证国 *
     */
    private String passCountry;
    /**
     * 第二证件 *
     */
    private String passSecondNum;
    /**
     * 票面价 *
     */
    private BigDecimal fcny;
    /**
     * 销售价 *
     */
    private BigDecimal scny;
    /**
     * 税总额 *
     */
    private BigDecimal taxAm;
    /**
     * 代理费 *
     */
    private BigDecimal agentAm;
    /**
     * 票面价差价 *
     */
    private BigDecimal fcnyDiff;
    /**
     * 销售价差价 *
     */
    private BigDecimal scnyDiff;
    /**
     * 税费总额差价 *
     */
    private BigDecimal taxAmDiff;
    /**
     * 改期费 *
     */
    private BigDecimal changeAm; 
    /**
     * 升舱费 *
     */
    private BigDecimal reschedualedAm;
    /**
     * 代理费率 *
     */
    private Integer agentCam;
    /**
     * 直减费率 *
     */
    private Integer agentZam;
    /**
     * 代理费差价 *
     */
    private Integer agentCamDiff;
    /**
     * 直减费差价 *
     */
    private Integer agentZamDiff;
    /**
     * 居住地街道 *
     */
    private String docaStreetr;
    /**
     * 居住地城市 *
     */
    private String docaCityr;
    /**
     * 居住地州/省 *
     */
    private String docaStater;
    /**
     * 居住地邮编 *
     */
    private String docaZipCoder;
    /**
     * 目的地街道 *
     */
    private String docaStreetd;
    /**
     * 目的地城市 *
     */
    private String docaCityd;
    /**
     * 目的地州/省 *
     */
    private String docaStated;
    /**
     * 目的地邮编 *
     */
    private String docaZipCoded;
    /**
     * 机票订单号 *
     */
    private String flightOrderNo;
    /**
     * 旅客類型 ADT成人 CHD儿童 IFT婴儿*
     */
    private String passengerTp;
    /**
     * 联系人电话 *
     */
    private String contactTel;
    /**
     * 联系人电话国家码
     */
    private String contactTelCountry;
    /**
     * 联系邮箱 *
     */
    private String contactEmail;
    /**
     * 币种*
     */
    private String currency;
    /**
     * 是否申请婴儿摇篮
     */
    private String babyCradle;
    /**
     * 客票 *
     */
    private Set<TicketDO> tickets;
    /**
     * 税项 *
     */
    private Set<TaxFeeDO> taxFees;
    /**
     * 航段 *
     */
    private Set<SegmentDO> segments;
    /**
     * 监护人的旅客序号*
     */
    private Integer guardianID;

    /**
     * 监护人姓名
     */
    private String guardianName;

    private String passengerFullName;

    /*
     * 促销码
     * */
    private String promoCode;
    /*
     * 促销类型
     * */
    private String promoType;
    /**
     * 优惠金额币种
     *
     */
    private String promoCurrency;
    /*
     * 优惠金额
     * */
    private BigDecimal promoAmount;

    /**
     * 会员卡航空公司
     * @return
     */
    private String ffpAirline;

    public Long getPassengerId() {
        return passengerId;
    }

    public void setPassengerId(Long passengerId) {
        this.passengerId = passengerId;
    }

    public String getBabyCradle() {
        return babyCradle;
    }

    public void setBabyCradle(String babyCradle) {
        this.babyCradle = babyCradle;
    }

    public Long getOldPassengerId() {
        return oldPassengerId;
    }

    public void setOldPassengerId(Long oldPassengerId) {
        this.oldPassengerId = oldPassengerId;
    }

    public Integer getModifySt() {
        return modifySt;
    }

    public void setModifySt(Integer modifySt) {
        this.modifySt = modifySt;
    }

    public String getTktNo() {
        return tktNo;
    }

    public void setTktNo(String tktNo) {
        this.tktNo = tktNo;
    }

    public String getPassengerFirstName() {
        return passengerFirstName;
    }

    public void setPassengerFirstName(String passengerFirstName) {
        this.passengerFirstName = passengerFirstName;
    }

    public String getPassengerMiddleName() {
        if (passengerMiddleName == null) {
            return "";
        } else {
            return passengerMiddleName;
        }
    }

    public void setPassengerMiddleName(String passengerMiddleName) {
        this.passengerMiddleName = passengerMiddleName;
    }

    public String getPassengerLastName() {
        return passengerLastName;
    }

    public void setPassengerLastName(String passengerLastName) {
        this.passengerLastName = passengerLastName;
    }

    public String getPassengerBirthday() {
        return passengerBirthday;
    }

    public void setPassengerBirthday(String passengerBirthday) {
        this.passengerBirthday = passengerBirthday;
    }

    public String getPassengerSex() {
        return passengerSex;
    }

    public void setPassengerSex(String passengerSex) {
        this.passengerSex = passengerSex;
    }

    public String getCountry() {
        return country;
    }

    public void setCountry(String country) {
        this.country = country;
    }

    public String getFfp() {
        return ffp;
    }

    public void setFfp(String ffp) {
        this.ffp = ffp;
    }

    public String getPassTp() {
        return passTp;
    }

    public void setPassTp(String passTp) {
        this.passTp = passTp;
    }

    public String getPassNo() {
        return passNo;
    }

    public void setPassNo(String passNo) {
        this.passNo = passNo;
    }

    public String getPassValidDt() {
        return passValidDt;
    }

    public void setPassValidDt(String passValidDt) {
        this.passValidDt = passValidDt;
    }

    public String getPassCountry() {
        return passCountry;
    }

    public void setPassCountry(String passCountry) {
        this.passCountry = passCountry;
    }

    public String getPassSecondNum() {
        return passSecondNum;
    }

    public void setPassSecondNum(String passSecondNum) {
        this.passSecondNum = passSecondNum;
    }

    public BigDecimal getFcny() {
        return fcny;
    }

    public void setFcny(BigDecimal fcny) {
        this.fcny = fcny;
    }

    public BigDecimal getScny() {
        return scny;
    }

    public void setScny(BigDecimal scny) {
        this.scny = scny;
    }

    public BigDecimal getTaxAm() {
        return taxAm;
    }

    public void setTaxAm(BigDecimal taxAm) {
        this.taxAm = taxAm;
    }

    public BigDecimal getAgentAm() {
        return agentAm;
    }

    public void setAgentAm(BigDecimal agentAm) {
        this.agentAm = agentAm;
    }

    public BigDecimal getFcnyDiff() {
        return fcnyDiff;
    }

    public void setFcnyDiff(BigDecimal fcnyDiff) {
        this.fcnyDiff = fcnyDiff;
    }

    public BigDecimal getScnyDiff() {
        return scnyDiff;
    }

    public void setScnyDiff(BigDecimal scnyDiff) {
        this.scnyDiff = scnyDiff;
    }

    public BigDecimal getTaxAmDiff() {
        return taxAmDiff;
    }

    public void setTaxAmDiff(BigDecimal taxAmDiff) {
        this.taxAmDiff = taxAmDiff;
    }

    public BigDecimal getChangeAm() {
        return changeAm;
    }

    public void setChangeAm(BigDecimal changeAm) {
        this.changeAm = changeAm;
    }

    public BigDecimal getReschedualedAm() {
        return reschedualedAm;
    }

    public void setReschedualedAm(BigDecimal reschedualedAm) {
        this.reschedualedAm = reschedualedAm;
    }

    public Integer getAgentCam() {
        return agentCam;
    }

    public void setAgentCam(Integer agentCam) {
        this.agentCam = agentCam;
    }

    public Integer getAgentZam() {
        return agentZam;
    }

    public void setAgentZam(Integer agentZam) {
        this.agentZam = agentZam;
    }

    public Integer getAgentCamDiff() {
        return agentCamDiff;
    }

    public void setAgentCamDiff(Integer agentCamDiff) {
        this.agentCamDiff = agentCamDiff;
    }

    public Integer getAgentZamDiff() {
        return agentZamDiff;
    }

    public void setAgentZamDiff(Integer agentZamDiff) {
        this.agentZamDiff = agentZamDiff;
    }

    public String getDocaStreetr() {
        return docaStreetr;
    }

    public void setDocaStreetr(String docaStreetr) {
        this.docaStreetr = docaStreetr;
    }

    public String getDocaCityr() {
        return docaCityr;
    }

    public void setDocaCityr(String docaCityr) {
        this.docaCityr = docaCityr;
    }

    public String getDocaStater() {
        return docaStater;
    }

    public void setDocaStater(String docaStater) {
        this.docaStater = docaStater;
    }

    public String getDocaZipCoder() {
        return docaZipCoder;
    }

    public void setDocaZipCoder(String docaZipCoder) {
        this.docaZipCoder = docaZipCoder;
    }

    public String getDocaStreetd() {
        return docaStreetd;
    }

    public void setDocaStreetd(String docaStreetd) {
        this.docaStreetd = docaStreetd;
    }

    public String getDocaCityd() {
        return docaCityd;
    }

    public void setDocaCityd(String docaCityd) {
        this.docaCityd = docaCityd;
    }

    public String getDocaStated() {
        return docaStated;
    }

    public void setDocaStated(String docaStated) {
        this.docaStated = docaStated;
    }

    public String getDocaZipCoded() {
        return docaZipCoded;
    }

    public void setDocaZipCoded(String docaZipCoded) {
        this.docaZipCoded = docaZipCoded;
    }

    public String getFlightOrderNo() {
        return flightOrderNo;
    }

    public void setFlightOrderNo(String flightOrderNo) {
        this.flightOrderNo = flightOrderNo;
    }

    public String getPassengerTp() {
        return passengerTp;
    }

    public void setPassengerTp(String passengerTp) {
        this.passengerTp = passengerTp;
    }

    public String getContactTel() {
        return contactTel;
    }

    public void setContactTel(String contactTel) {
        this.contactTel = contactTel;
    }

    public String getContactTelCountry() {
        return contactTelCountry;
    }

    public void setContactTelCountry(String contactTelCountry) {
        this.contactTelCountry = contactTelCountry;
    }

    public String getContactEmail() {
        return contactEmail;
    }

    public void setContactEmail(String contactEmail) {
        this.contactEmail = contactEmail;
    }

    public Set<TicketDO> getTickets() {
        return tickets;
    }

    String getTicketNos() {
        if (this.tickets != null && !tickets.isEmpty()) {
            if (tickets.size() == 1) {
                return tickets.iterator().next().getTktNo();
            }
            //获取所有的的票号(不包含航空代码和分隔符)
            Set<Long> sortTickets = new TreeSet<>();
            for (TicketDO ticket : this.tickets) {
                String ticketNo = ticket.getTktNo();
                String ticketNoWithoutAirline = ticketNoWithAirline(ticketNo);
                Long longTicketNo = Long.parseLong(ticketNoWithoutAirline);
                sortTickets.add(longTicketNo);
            }

            int size = sortTickets.size();
            Iterator<Long> ticketNoIt = sortTickets.iterator();
            //相同的联票号, 只返回一个票号
            if (size == 1) {
                return tickets.iterator().next().getTktNo();
            }

            //对所有机票号组装成格式 781-123456781/781-123456782/781-123456783
            StringBuilder ticketNos = new StringBuilder();

            for (int i = 0; i < size; i++) {
                Long ticketNo = ticketNoIt.next();
                for (TicketDO ticket : this.tickets) {
                    String ticketNoStr = ticket.getTktNo();
                    if (ticketNoStr.contains(String.valueOf(ticketNo))) {
                        ticketNos.append(ticketNoStr);
                        if (i < size - 1) {
                            ticketNos.append("/");
                        }
                        break;
                    }
                }
            }
            return ticketNos.toString();
        }
        return "";
    }

    private String ticketNoWithAirline(String ticketNo) {
        if (ticketNo.contains("-")) {
            return ticketNo.substring(ticketNo.indexOf('-') + 1);
        }
        return ticketNo.substring(3);
    }

    public void setTickets(Set<TicketDO> tickets) {
        this.tickets = tickets;
    }

    public void addTicket(TicketDO ticket) {
        if (this.tickets == null) {
            this.tickets = new HashSet();
        }
        this.tickets.add(ticket);
    }

    public Set<TaxFeeDO> getTaxFees() {
        return taxFees;
    }

    public void setTaxFees(Set<TaxFeeDO> taxFees) {
        this.taxFees = taxFees;
    }

    public void addTax(TaxFeeDO tax) {
        if (this.taxFees == null) {
            this.taxFees = new HashSet();
        }
        this.taxFees.add(tax);
    }

    public Set<SegmentDO> getSegments() {
        return segments;
    }

    public void setSegments(Set<SegmentDO> segments) {
        this.segments = segments;
    }

    public void addSegment(SegmentDO segment) {
        if (this.segments == null) {
            this.segments = new HashSet();
        }
        this.segments.add(segment);
    }

    @Override
    public String toString() {
        return "PaxDO [passengerId=" + passengerId + ", oldPassengerId="
                + oldPassengerId + ", modifySt=" + modifySt + ", tktNo="
                + tktNo + ", passengerFirstName=" + passengerFirstName
                + ", passengerMiddleName=" + passengerMiddleName
                + ", passengerLastName=" + passengerLastName
                + ", passengerBirthday=" + passengerBirthday
                + ", passengerSex=" + passengerSex + ", country=" + country
                + ", ffp=" + ffp + ", passTp=" + passTp + ", passNo=" + passNo
                + ", passValidDt=" + passValidDt + ", passCountry="
                + passCountry + ", passSecondNum=" + passSecondNum + ", fcny="
                + fcny + ", scny=" + scny + ", taxAm=" + taxAm + ", agentAm="
                + agentAm + ", fcnyDiff=" + fcnyDiff + ", scnyDiff=" + scnyDiff
                + ", taxAmDiff=" + taxAmDiff + ", changeAm=" + changeAm
                + ", reschedualedAm=" + reschedualedAm + ", agentCam="
                + agentCam + ", agentZam=" + agentZam + ", agentCamDiff="
                + agentCamDiff + ", agentZamDiff=" + agentZamDiff
                + ", docaStreetr=" + docaStreetr + ", docaCityr=" + docaCityr
                + ", docaStater=" + docaStater + ", docaZipCoder="
                + docaZipCoder + ", docaStreetd=" + docaStreetd
                + ", docaCityd=" + docaCityd + ", docaStated=" + docaStated
                + ", docaZipCoded=" + docaZipCoded + ", flightOrderNo="
                + flightOrderNo + ", tickets=" + tickets + ", taxFees="
                + taxFees + ", segments=" + segments + "]";
    }

    public String getCurrency() {
        return currency;
    }

    public void setCurrency(String currency) {
        this.currency = currency;
    }

    public Integer getGuardianID() {
        return guardianID;
    }

    public void setGuardianID(Integer guardianID) {
        this.guardianID = guardianID;
    }
    /**
     * 积分总额 *
     */
    private BigDecimal pointAmount;

    public BigDecimal getPointAmount() {
        return pointAmount;
    }

    public void setPointAmount(BigDecimal pointAmount) {
        this.pointAmount = pointAmount;
    }
    /**
     * 积分种类*
     */
    private String pointTp;

    public String getPointTp() {
        return pointTp;
    }

    public void setPointTp(String pointTp) {
        this.pointTp = pointTp;
    }

    public String getPassengerFullName() {
        return passengerFullName;
    }

    public void setPassengerFullName(String passengerFullName) {
        this.passengerFullName = passengerFullName;
    }

    public String getGuardianName() {
        return guardianName;
    }

    public void setGuardianName(String guardianName) {
        this.guardianName = guardianName;
    }

    public String getFfpAirline() {
		return ffpAirline;
	}

	public void setFfpAirline(String ffpAirline) {
		this.ffpAirline = ffpAirline;
	}
	
    public String getPaxFullName() {
        String fullName = (this.passengerLastName == null ? "" : this.passengerLastName + "/")
                + (this.passengerFirstName == null ? "" : this.passengerFirstName)
                + (this.passengerMiddleName == null ? "" : this.passengerMiddleName);
        return fullName.toUpperCase();
    }

    public String getPromoCode() {
        return promoCode;
    }

    public String getPromoType() {
        return promoType;
    }

    public String getPromoCurrency() {
        return promoCurrency;
    }

    public BigDecimal getPromoAmount() {
        return promoAmount;
    }

    /**
     * @param promoCode the promoCode to set
     */
    public void setPromoCode(String promoCode) {
        this.promoCode = promoCode;
    }

    /**
     * @param promoType the promoType to set
     */
    public void setPromoType(String promoType) {
        this.promoType = promoType;
    }

    /**
     * @param promoCurrency the promoCurrency to set
     */
    public void setPromoCurrency(String promoCurrency) {
        this.promoCurrency = promoCurrency;
    }

    /**
     * @param promoAmount the promoAmount to set
     */
    public void setPromoAmount(BigDecimal promoAmount) {
        this.promoAmount = promoAmount;
    }

    @Override
    public int hashCode() {
        int hash = 3;
        hash = 89 * hash + Objects.hashCode(this.passengerId);
        hash = 89 * hash + Objects.hashCode(this.tktNo);
        hash = 89 * hash + Objects.hashCode(this.passengerFirstName);
        hash = 89 * hash + Objects.hashCode(this.passengerLastName);
        return hash;
    }

    /**
     * 如果要更改这个方法请通知 youguilin@ceair.com
     *
     * @param obj
     * @return
     */
    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final com.ceair.flight.refund.location.model.PaxDO other = (com.ceair.flight.refund.location.model.PaxDO) obj;
        if (!Objects.equals(this.passengerId, other.passengerId)) {
            return false;
        }
        if (!Objects.equals(this.tktNo, other.tktNo)) {
            return false;
        }
        if (!Objects.equals(this.passengerFirstName, other.passengerFirstName)) {
            return false;
        }
        if (!Objects.equals(this.passengerLastName, other.passengerLastName)) {
            return false;
        }
        return true;
    }

}
